﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using Model;

namespace BusinessLogic
{
    public class GetSpecialCampaign : BaseCommand<List<acm_campaign>>
    {
        public int _id { get; set; }
        public int _is_special;
        public DateTime _dt;

        public GetSpecialCampaign(DateTime EffectiveDate, int seriesId, int is_special)
        {
            _dt = EffectiveDate;
            _id = seriesId;
            _is_special = is_special;

            SetQuery("exec ACM_GET_CAMPAIGN @effectiveDate,@seriesId,@is_special");

            cmd.Parameters.AddWithValue("effectiveDate", _dt);
            cmd.Parameters.AddWithValue("seriesId", _id);
            cmd.Parameters.AddWithValue("is_special", _is_special);
        }

        public override void Command()
        {
            Result = new List<acm_campaign>();
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                acm_campaign row = new acm_campaign();
                row.id = GetNullableInt(dr, 0);
                row.campaign_name = GetNullableString(dr, 1);
                row.campaign_desc = GetNullableString(dr, 2);
                row.start_date = GetNullableDateTime(dr, 3);
                row.end_date = GetNullableDateTime(dr, 4);
                row.series_id_list = GetNullableString(dr, 5);
                row.promotion_amount = GetNullableDecimal(dr, 6);
                row.promotion_note4 = GetNullableInt(dr, 7);

                Result.Add(row);
            }
        }
    }
}
